<template>
  <div>
    <h1>标题：{{ article.title }}</h1>
    <p>内容：{{ article.body }}</p>
  </div>
</template>
<script>
import axios from "axios";
export default {
  name: "ArticlePage",
  async asyncData(context) {
    const res = await axios({
      method: "GET",
      url: "http://localhost:3000/data.json",
    });
    //根据上下文对象获取params数据
    const id = Number.parseInt(context.params.id);
    return {
      article: res.data.posts.find((item) => item.id === id),
    };
  },
};
</script>